package org.edu.modules.jxrw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.edu.modules.jxrw.entity.VeJwJxrw;
import org.edu.modules.jxrw.mapper.VeJwJxrwMapper;
import org.edu.modules.jxrw.service.IVeJwJxrwService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.List;

/**
 * @Description: ve_jw_jxrw
 * @Author: jeecg-boot
 * @Date:   2021-05-07
 * @Version: V1.0
 */
@Service
public class VeJwJxrwServiceImpl extends ServiceImpl<VeJwJxrwMapper, VeJwJxrw> implements IVeJwJxrwService {

    @Override
    public void changePublishByIds(String ids, int status) {
        List<String> list = Arrays.asList(ids.split(","));
        if(status==1){
            for (String str:list) {
                //判断状态是否通过
                if(this.getById(Integer.parseInt(str)).getCheckstatus()!=1){
                    continue;
                }
                baseMapper.updateById(new VeJwJxrw().setId(Integer.parseInt(str)).setIspublish(status));
            }
        }else{
            for (String str:list) {
                baseMapper.updateById(new VeJwJxrw().setId(Integer.parseInt(str)).setIspublish(status));
            }
        }

    }

    @Override
    public List<VeJwJxrw> getBySemid(int semid) {
        return baseMapper.selectList(new QueryWrapper<VeJwJxrw>().eq("semId",semid));
    }

    @Override
    public List<VeJwJxrw> getByCondition(VeJwJxrw jxrw) {
        LambdaQueryWrapper<VeJwJxrw> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(VeJwJxrw::getSemid,jxrw.getSemid())
                .eq(VeJwJxrw::getFalid,jxrw.getFalid())
                .eq(VeJwJxrw::getSpecid,jxrw.getSpecid())
                .eq(VeJwJxrw::getGradeid,jxrw.getGradeid())
        ;
        if(jxrw.getJxbid()!=null){
            queryWrapper.eq(VeJwJxrw::getJxbid,jxrw.getJxbid());
        }
        if(jxrw.getKcid()!=null){
            queryWrapper.eq(VeJwJxrw::getKcid,jxrw.getKcid());
        }

        return baseMapper.selectList(queryWrapper);
    }
}
